package com.twu.biblioteca;

import java.util.HashMap;

public class LogInSystem {
    private HashMap<String, User> users;
    private String currentUser;

    public LogInSystem(HashMap<String, User> users) {
        this.users = users;
        this.currentUser = null;
    }

    public LogInSystem(HashMap<String, User> users, String currentUser) {
        this.users = users;
        this.currentUser = currentUser;
    }

    public String getUserInfo() {
        if (users.containsKey(currentUser))
            return users.get(currentUser).toString();
        return null;
    }

    public boolean validateUsernameAndPassword(String username, String password) {
        if (users.containsKey(username) &&
                users.get(username).validatePassword(password)) {
            currentUser = username;
            return true;
        }
        return false;
    }

    public boolean isUserLoggedIn() {
        return (currentUser==null) ?
                false : true;
    }
}
